//
//  SignupViewController.swift
//  ModernFoodWebsite
//
//  Created by apple on 16/5/29.
//  Copyright © 2016年 Lonnie. All rights reserved.
//

import UIKit
import CoreData
class SignupViewController: UIViewController {
    var backButton:UIButton?
    @IBOutlet weak var phoneTextField: UITextField!
    override func viewDidLoad() {
        super.viewDidLoad()
        backButton = addBackButton()
        backButton?.addTarget(self, action: #selector(SignupViewController.back(_:)), forControlEvents: .TouchUpInside)
        phoneTextField.configureToCommonStyle()
        authCodeTextField.configureToCommonStyle()
        nicknameTextField.configureToCommonStyle()
        passwordTextField.configureToCommonStyle()
        phoneTextField.addLeftView("auth_account_icon")
        authCodeTextField.addLeftView("auth_authcode_icon")
        nicknameTextField.addLeftView("auth_name_icon")
        passwordTextField.addLeftView("auth_password_icon")
    }
    
    func back(b:UIButton) {
        dismissViewControllerAnimated(true) { 
            
        }
    }
    
    @IBOutlet weak var authCodeTextField: UITextField!
    
    @IBOutlet weak var nicknameTextField: UITextField!
    
    @IBOutlet weak var passwordTextField: UITextField!
    
    @IBAction func signup(sender: AnyObject) {
        let phone = phoneTextField.text
        let password = passwordTextField.text
        let nickname = nicknameTextField.text
        let account:Account = NSEntityDescription.insertNewObjectForEntityForName("Account", inManagedObjectContext: DataController.shareInstance.managedObjectContext) as! Account
        account.phone = phone
        account.password = password
        account.nickname = nickname
        DataControllerSaveContext()
        print("%d")
        back(backButton!)
    }
    
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        self.view.endEditing(true)
    }
}
